import Vue from "vue";

import VueRouter from 'vue-router';
import BaseLayout from "@/components/frame/BaseLayout.vue";
import BaseLayoutWithoutHeader from "@/components/frame/BaseLayoutWithoutHeader.vue";

Vue.use(VueRouter);

export const frame_routes = [
    {
        path: '/',
        name: 'base',
        redirect: '/index',
        component: BaseLayout,
        children:[
            {
                name: 'index',
                path: '/index',
                title:'系统首页',
                meta:{title:'系统首页',icon:'home'},
                component: ()=> import("@/modules/views/index.vue")
            },{
                path: '/helloWorld',
                name: 'helloWord',
                title:'Hello Word',
                meta:{title:'Hello Word',icon:'video-camera'},
                component: () => import('@/components/HelloWorld')  //按需加载，跳转到这个页面再加载
            },{
                path: '/sys',
                name: 'sys',
                title: '系统设置',
                meta:{title:'系统设置',icon:'setting'},
                component: BaseLayoutWithoutHeader,
                children:[
                   {
                        name: 'user',
                        path: '/user',
                       title:'成员管理',
                        meta:{title:'成员管理',icon:'user'},
                        component: ()=> import("@/modules/views/personal")
                    }, {
                        name: 'group',
                        path: '/group',
                        title:'福利群管理',
                        meta:{title:'福利群管理',icon:'usergroup-add'},
                        component: ()=> import("@/modules/views/welfareGroup")
                    },/*{
                        name: 'team',
                        path: '/team',
                        meta:{title:'团队管理',icon:'team'},
                        component: ()=> import("@/modules/views/index.vue")
                    },*/{
                        name: 'role',
                        path: '/role',
                        title:'职务管理',
                        meta: {title: '职务管理',icon: 'contacts'},
                        component: ()=> import("@/modules/views/system/role/index.vue")
                    }
                ]
            }
        ]
    },
];

export const user_routes = [
    {
        name: 'login',
        path: '/login',
        component: ()=> import("@/modules/views/system/login")
    }
];

export const error_routes = [
    {
        name: 'error',
        path: '/error',
        component: BaseLayout,
        redirect:'/401',
        children:[
            {
                name:'401',
                path:'/401',
                component:()=>import("@/components/error/TokenError.vue")
            }
        ]
    }
]


const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

export const router = new VueRouter({
    mode: 'history',
    routes: [...frame_routes,...user_routes,...error_routes]
});
